/**************************************************************************************************
	$Header: /pub/cvsroot/mydns/src/mydns/error.c,v 1.7 2002/12/08 07:49:43 bboy Exp $
	error.c: Routines to send error replies.

	Copyright (C) 2002  Don Moore <bboy@bboy.net>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at Your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**************************************************************************************************/

#include "named.h"


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	ERR_REASON_STR
	Returns a string describing 'reason'.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
char *
err_reason_str(reason)
	enum task_error_t reason;
{
	switch (reason)
	{
		case ERR_NONE: return ("-");
		case ERR_ZONE_NOT_FOUND: return ((char *)_("Zone_not_found"));
		case ERR_NO_AXFR: return ((char *)_("AXFR_disabled"));
		case ERR_RR_NAME_TOO_LONG: return ((char *)_("Name_too_long_in_RR"));
		case ERR_Q_BUFFER_OVERFLOW: return ((char *)_("Input_name_buffer_overflow"));
		case ERR_Q_INVALID_COMPRESSION: return ((char *)_("Unknown_compression_method"));
		case ERR_Q_NAME_TOO_LONG: return ((char *)_("Question_name_too_long"));
		case ERR_NO_CLASS: return ((char *)_("Unknown_class"));
		case ERR_NAME_FORMAT: return ((char *)_("Invalid_name_format"));
		case ERR_TIMEOUT: return ((char *)_("Communications_timeout"));
		case ERR_BROKEN_GLUE: return ((char *)_("Malformed_glue"));
	}
	return ((char *)_("Unknown"));
}
/*--- err_reason_str() --------------------------------------------------------------------------*/


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	_DNSERROR_INTERNAL
	Generate error response for query and set status to NEED_SEND.  Always returns -1, as a
	convenience.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
int
_dnserror_internal(t, rcode, reason, filename, lineno)
	TASK *t;								/* The failed task */
	dns_rcode_t rcode;				/* The return code to use, such as DNS_R_SERVFAIL, etc. */
	enum task_error_t reason;		/* Further explanation of the error */
	const char *filename;
	unsigned int lineno;
{
#if DEBUG
	Debug("%s: %s %s from %s:%u",
			desctask(t), mydns_rcode_str(rcode), err_reason_str(reason), filename, lineno);
#endif

	t->hdr.rcode = rcode;
	t->status = NEED_WRITE;
	t->reason = reason;

	return (-1);
}
/*--- _dnserror_internal() ----------------------------------------------------------------------*/

/* vi:set ts=3: */
/* NEED_PO */
